﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
@using LeSoft.Application.Code;
<script>
    var _State = "", Type = "1";
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId"
    $(function () {
            InitialPage();
            GetTree(); 
            GetGrid();
    })
 
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 181.5);

            }, 200);
             e.stopPropagation(); 
        });
        //初始化时间

        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
        //组织机构

        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            description: "=选择=",
            click: function (item) {
                
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
        $("#Category").ComboBox({
            data: [{ "key": "1", "value": "初次申请" }, { "key": "2", "value": "再次申请" }, { "key": "3", "value": "续租申请" }, { "key": "4", "value": "再次续租申请" }],
            id: "key",
            text: "value",
            description: "=选择业务状态=",
            height: "200px",
            click: function (item) {              
                SearchEvent();
            }
        });
    }

    function GetTree() { 
        var item = {
            height: $(window).height() - 55.5,
            url: "../../QualificationManage/FirstTrial/GetTreeListTojson",
            onnodeclick: function (item) {
                switch (item.id) {
                    case "All":
                        _State = -1;
                        break;
                    case "FirstCheck":
                        _State = 1;
                        break;
                    case "AgainCheck":
                        _State = 2;
                        break;
                    case "AllCheck":
                        _State = -2;
                        break;
                    case "UnChecked":
                        _State = 3;
                        break;
                    case "Checked":
                        _State = 4;
                        break;
                    default: break; 
                }
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
        
    }

    function GetGrid() {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable");
        var queryJson = {
            State: _State,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val() + " 23:59:59",
            Name: $("#Name").val(),
            IDCard: $("#IDCard").val(),
            Category: $("#Category").attr("data-value"),
            Phone: $("#Phone").val()
        };
        $gridTable.jqGrid({
            url: "../../QualificationManage/FirstTrial/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true, 
            colModel: [
                { label: "主键", name: "id", hidden: true },
                 { label: "姓名", name: "name", index: "name", width: 200, align: "center", sortable: false },
                { label: "身份证号码", name: "idcard", index: "idcard", width: 200, align: "center", sortable: false },
                
                { label: "手机号", name: "phone", index: "phone", width: 200, align: "center", sortable: false },
                {
                    label: "性别", name: "sex", index: "sex", width: 50, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        switch (cellvalue) {
                            case 1:
                                return "男";
                            case 2:
                                return "女";
                            default: return cellvalue;

                        }
                    }
                },
                { label: "单据编号", name: "code", index: "code", width: 200, align: "center", sortable: false },
                { label: "单据时间", name: "date", index: "date", width: 200, align: "center", sortable: false },
                {
                    label: "业务类型", name: "category", index: "category", width: 200, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        var Msg = "";
                        switch (cellvalue) {
                            case 1: Msg = "初次申请";
                                break;
                            case 2: Msg = "再次申请";
                                break;
                            case 3: Msg = "续租申请";
                                break;
                            case 4: Msg = "再次续租申请";
                                break;
                            default: Msg = "---";
                                break;
                        }
                        return Msg;
                    }
                }, 
               
                {
                    label: "单据状态", name: "state", index: "state", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        var Msg = "<span  class='label' style='background-color:";
                        switch (cellvalue) {
                            case 1:
                            case 2: Msg += "#BCD186'>" + "待审核";
                                break;
                            case 3: Msg += "#f00'>" + "未通过";
                                break;
                            case 4:
                            case 5:
                            case 6:
                            case 7:
                            case 10:
                            case 8: Msg += "#5CB85C'>" + "通过";
                                break;
                            
                            case 9: Msg += "#ccc'>" + "客户撤回";
                                break;
                            default: return "cellvalue";
                                break;
                        }
                        Msg += "</span>";
                        return Msg;
                    }
                },
                
                
                { label: "提交时间", name: "date", index: "date", width: 200, align: "center", sortable: false },
                { label: "提交次数", name: "submitcount", index: "submitcount", width: 100, align: "center", sortable: false },
                { label: "未通过原因", name: "chcekmemo", index: "chcekmemo", width: 200, align: "center", sortable: false }
                 ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'date',
            sortorder: 'desc',
            rownumbers: true,
            gridview: true,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $(".ui-filter-text").trigger("click");
            $('#btn_Reset').trigger("click");
        });
        $("#btn_Reset").click(function () { 
            $("#Name").val("");
            $("#IDCard").val("");
            $("#Phone").val("");

        })

    }
    //查询表格函数
    function SearchEvent() {
        var queryJson = {
            State: _State,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val() + " 23:59:59",
            Name: $("#Name").val(),
            IDCard: $("#IDCard").val(),
            Category: $("#Category").attr("data-value"),
            Phone: $("#Phone").val()
        };
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../QualificationManage/FirstTrial/GetPageList",
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
        $("#Name").val("");
        $("#IDCard").val("");
        $("#Phone").val("");
    }
    function btn_export() {
        var queryJson = {
            State: _State,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val() + " 23:59:59",
            Name: $("#Name").val(),
            IDCard: $("#IDCard").val(),
            Category: $("#Category").attr("data-value"),
            Phone: $("#Phone").val()
        };        
        location.href = "../../QualificationManage/FirstTrial/GetExportList?queryJson=" + JSON.stringify(queryJson);
    }
    function btn_detail()
    {
        var keyValue = $("#gridTable").jqGridRowValue("code"); 
        if (checkedRow(keyValue))
        {
            top.tablist.newTab({
                id: "FirstTrialForm-" + keyValue,
                title: '单据详情【初审】',
                closed: true,
                icon: "fa fa-eye",
                url: top.contentPath + '/QualificationManage/FirstTrial/Form?keyValue=' + keyValue  
            });
       }

    }
    //材料配置
    function btn_MaterialSetting()
    {
        
            dialogOpen({
                id: "MSettingForm",
                title: '上传资料设置', 
                url: '/QualificationManage/FirstTrial/MSettingForm',
                width: "1100px",
                height: "750px",
                btn: ["关闭"],
                callBack: function (iframeId) {
                    top.frames["MSettingForm"].AcceptClick();
                }
            })
      
    }
    function btn_MaterialRuleSetting()
    {
        dialogOpen({
            id: "MSettingRuleForm",
            title: '材料规则配置', 
            url: '/QualificationManage/FirstTrial/MSettingRuleForm',
            width: "1100px",
            height: "750px",
            btn: null,
            callBack: function (iframeId) {
                top.frames["MSettingForm"].AcceptClick();
            }
        })
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">单据状态</div>
            <div id="itemTree1">
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search ">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">姓名：</td>
                                                <td class="formValue">
                                                    <input id="Name" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">身份证号：</td>
                                                <td class="formValue">
                                                    <input id="IDCard" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">手机号：</td>
                                                <td class="formValue">
                                                    <input id="Phone" maxlength="20" type="text" class="form-control">
                                                </td>
                                            </tr>

                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="Category" type="selectTree" class="ui-select" style="width: 150px;"></div>
                            </td>

                        </tr>

                    </table>

                </div>

                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default " onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default " onclick="btn_detail()"><i class="fa fa-eye"></i>&nbsp;查看</a>
                        <a id="lr-export" class="btn btn-default" onclick="btn_export()"><i class="fa fa-sign-out"></i>&nbsp;导出</a>
                        <a id="lr-delete" class="btn btn-default" data-toggle="dropdown"><i class="fa fa-reorder"></i>&nbsp;更多操作<span class="caret"></span></a>
                        <ul class="dropdown-menu pull-right">
                            <li id="lr-type"><a onclick="btn_MaterialSetting()">&nbsp;上传资料设置</a></li>
                            <li id="lr-Item"><a onclick="btn_MaterialRuleSetting()">&nbsp;材料规则配置</a></li>
                         </ul>
                     </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>


            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>

        </div>
    </div>
</div>

